package com.xhhospital.servlet;

import com.xhhospital.dao.BrxxDao;
import com.xhhospital.entity.Brxx;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "EditBrxxServlet" ,urlPatterns = "/editbrxx")
public class EditBrxxServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String id=request.getParameter("jzkh");
        int jzkh=Integer.parseInt(id);
        List<Brxx> list=new ArrayList<Brxx>();
        list= BrxxDao.getBrxxByBh(jzkh);//根据传递编号，返回实体对象
        if (list!=null){
            //请求转发
            request.setAttribute("editbrxx",list);
            request.getRequestDispatcher("/xiugai.jsp").forward(request,response);
        }
    }



    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        PrintWriter out=response.getWriter();
        //获取参数
        String id=request.getParameter("jzkh");
        int jzkh=Integer.parseInt(id);
        String brxm=request.getParameter("brxm");
        String brxb= request.getParameter("brxb");
        String jzks= request.getParameter("jzks");
        String ysxm= request.getParameter("ysxm");
        String lxfs= request.getParameter("lxfs");
        Brxx brxx=new Brxx();
        brxx.setJzkh(jzkh);
        brxx.setBrxm(brxm);
        brxx.setBrxb(brxb);
        brxx.setJzks(jzks);
        brxx.setYsxm(ysxm);
        brxx.setLxfs(lxfs);
        int bool= BrxxDao.updateBrxx(brxx);
        if(bool>0){
            response.sendRedirect("showedit1");
        }else{
            out.println("修改错误");
        }
    }
}